Declaration of an interface incl. method prototypes
Syntax |
---|
|
Meaning |
---|
declaration of an →interface (a feature of the →object-oriented programming), In the object oriented programming, the interface separates the interface specification from its implementation as a →class. This allows different implementations of a common interface specification. The keyword |
Good to know |
---|
You are able to declare only →method prototypes within an interface. See the following section "Declaration of a method prototype". An interface may be used as the type of a variable (see "Declaration of variables based on an interface"). Moreover, a function block or a →class can implement the interfaces (see "Declaration of a function block in ST"). An interface behaves as a →function block does. |
Declaration of a method prototype
A method prototype is a restricted declaration of a →method (with the implicit modifier PUBLIC
) for the use with an interface.
Overview for the syntax |
---|
|
In contrast to a method (see "Declaration of a method" for details), a method prototype may contain these elements only:
-
the name of the method prototype
-
optional: the data type of the method prototype (for a return value)
-
optional: the declaration of →input variables, →output variables and →in-/out variables
All other variables (e.g. →temporary variables) must not be declared in a method prototype.
Observe that no keywords (e.g. modifiers) and no body (hence, a code to execute) are defined in a method prototype as this is possible for a method.
Example 1: Interface with 2 method prototypes |
---|
|
Example 2: As example 1 with derived interfaces |
---|
|
Example 3 |
---|
|
More examples for interfaces are specified under "Examples on using interfaces and variables based on these interfaces (incl. assignments)".